/**
 * 
 */
package org.statewalker.parser.xhtml.parser;

import org.statewalker.dict.BaseDict;
import org.statewalker.parser.base.ParserFactory;
import org.statewalker.parser.xhtml.grammar.XHTMLCharactersEntities;
import org.statewalker.parser.xhtml.grammar.XHTMLDict;
import org.statewalker.parser.xhtml.grammar.XHTMLSpecialEntities;
import org.statewalker.parser.xhtml.grammar.XHTMLSymbolsEntities;
import org.statewalker.parser.xhtml.tokenizer.ScriptContentTokenizer;
import org.statewalker.parser.xhtml.tokenizer.StyleContentTokenizer;
import org.statewalker.parser.xhtml.validator.XHTMLValidatorFactory;
import org.statewalker.tokenizer.base.NewLineTokenizer;
import org.statewalker.tokenizer.base.SpaceTokenizer;
import org.statewalker.tokenizer.base.SpecialSymbolTokenizer;
import org.statewalker.tokenizer.base.WordTokenizer;
import org.statewalker.tokenizer.xml.EntityFactory;
import org.statewalker.tokenizer.xml.EntityReader;
import org.statewalker.tokenizer.xml.XMLTokenizer;

public class XhtmlParserFactory extends ParserFactory {

    public XhtmlParserFactory(XHTMLValidatorFactory validatorFactory) {
        super(validatorFactory);
    }

    @Override
    protected void bindTokenizers() {
        EntityFactory entityFactory = new EntityFactory();
        new XHTMLCharactersEntities(entityFactory);
        new XHTMLSymbolsEntities(entityFactory);
        new XHTMLSpecialEntities(entityFactory);
        EntityReader entityReader = new EntityReader(entityFactory, true);
        XMLTokenizer xmlTokenizer = new XMLTokenizer(entityReader);
        setTokenizers(
            BaseDict.ROOT,
            SpaceTokenizer.INSTANCE,
            WordTokenizer.INSTANCE,
            NewLineTokenizer.INSTANCE,
            xmlTokenizer,
            SpecialSymbolTokenizer.INSTANCE);
        setTokenizer(XHTMLDict.SCRIPT, ScriptContentTokenizer.INSTANCE);
        setTokenizer(XHTMLDict.STYLE, StyleContentTokenizer.INSTANCE);
    }

    @Override
    public XHTMLValidatorFactory getValidatorFactory() {
        return (XHTMLValidatorFactory) super.getValidatorFactory();
    }

    public XHTMLValidatorFactory getXhtmlValidatorFactory() {
        return getValidatorFactory();
    }

}